//
//  RXBaseController.swift
//  weibo
//
//  Created by uncle-R on 15/12/15.
//  Copyright © 2015年 uncle-R. All rights reserved.
//

import UIKit

class RXBaseController: UITableViewController,RXVistorViewDelegate{
    
    // 用户是否登录
    var userlog = RXUserAccount.userIslogin

    override func loadView() {
        
        userlog ? super.loadView() : setupVistorView()
    }
    
    
    
    func setupVistorView(){
        //设置一个view
        
         self.view = visitorView
        //设置代理
        visitorView.delegate = self
        
        if self is RXHomeViewController{
            //添加转轮动画
            visitorView.startRotationAnimation()
            //程序退到后台或者进入前台都会发出通知.
            //注册通知
            //监听到应用进入前台
            NSNotificationCenter.defaultCenter() .addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
            //监听到应用进入后台
              NSNotificationCenter.defaultCenter() .addObserver(self, selector: "didEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
        }
        else if self is RXMessageViewController{
             visitorView.setupVisitorInfo("visitordiscover_image_message", messageL: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            
        }
        else if self is RXDiscoverController{
            visitorView.setupVisitorInfo("visitordiscover_image_message", messageL: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            
        }
        else if self is RXProfileViewController{
            
            visitorView.setupVisitorInfo("visitordiscover_image_profile", messageL: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
            
        }
        
//        self.tableView.addSubview(view)
    }
    deinit{
        if self is RXHomeViewController{
        NSNotificationCenter.defaultCenter().removeObserver(self)
        }
    }
    
    ///监控到进去前台
    func didBecomeActive(){
        print(__FUNCTION__)
        //继续旋转
        visitorView .resumeAnimation()
        
    }
    //监控到退出后台
    func didEnterBackground(){
        print(__FUNCTION__)
        //暂停动画
        visitorView.pauseAnimation()
        
    }
    
    //MARK: - 实现访客界面的代理方法
    
    ///登录按钮
    func visitorViewLoginBtnClick() {
    
        
    let outhVC = RXOauthController()
        
        presentViewController(UINavigationController(rootViewController: outhVC), animated: true, completion: nil)
        
    }
    ///注册按钮.
    func visitorViewResgiterBtnClick() {
        
    }
    
    
  
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        ///设置导航栏左右按钮
       let leftBtn = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "registBtnClick")
       
        self.navigationItem.leftBarButtonItem = leftBtn
        
        let rightBtn = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLoginBtnClick")
        
        self.navigationItem.rightBarButtonItem = rightBtn

    }
    
    
    //MARK: - 实现访客界面登录按钮的代理方法
  
    
    private var visitorView : RXVistorView = RXVistorView()
    
    
   
}
